//
// Copyright (C) 2008 Jackson Harper (jackson@ximian.com)

// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
//
//

using System;
using System.Text;


namespace Grr.Model {

	public static class GrurrahString {

		public static string ToDbString (string str)
		{
            StringBuilder res = new StringBuilder(str.Length);

            for (int i = 0; i < str.Length; i++)
            {
                switch (str[i])
                {
                    case '_':
                        res.Append(' ');
                        break;
                    case '\"':
                    case '\'':
                        break;
                    default:
                        res.Append(str[i]);
                        break;
                }
            }
            return res.ToString();
		}

		public static string ToUserString (string str)
		{
			return Uri.UnescapeDataString (str.Replace ('_', ' '));
		}

		public static string ToUriString (string str)
		{
            StringBuilder res = new StringBuilder (str.Length);

            for (int i = 0; i < str.Length; i++)
            {
                switch (str[i])
                {
                    case ' ':
                        res.Append('_');
                        break;
                    case '\'':
                        res.Append("%27");
                        break;
                    default:
                        res.Append(str[i]);
                        break;
                }
            }
            return res.ToString ();
		}
	}

}


